<?php

// CALUCATIONS FOR SYSTEM GROSS & APERTURE AREAS
if (get_post_meta($post->ID, 'RPCollectorModel', true) == ThermoPower-VHP10) {
	$collectoraperture = 10.61;
	$collectorgross = 18.21;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == ThermoPower-VHP20) {
	$collectoraperture = 21.23;
	$collectorgross = 37.04;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == ThermoPower-VHP30) {
	$collectoraperture = 31.84;
	$collectorgross = 55.86;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == ThermoPower-VDF20) {
	$collectoraperture = 19.38;
	$collectorgross = 26.95;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == ThermoPower-VDF30) {
	$collectoraperture = 28.78;
	$collectorgross = 39.24;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPowerPlus-SU2) {
	$collectoraperture = 20.17;
	$collectorgross = 21.42;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPowerPlus-SU24) {
	$collectoraperture = 24.43;
	$collectorgross = 25.93;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPowerPlus-AA3) {
	$collectoraperture = 28.96;
	$collectorgross = 30.92;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPowerPlus-AU32) {
	$collectoraperture = 30.53;
	$collectorgross = 31.78;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPowerPlus-AU40) {
	$collectoraperture = 37.44;
	$collectorgross = 38.87;
} elseif (get_post_meta($post->ID, 'RPCollectorModel', true) == TitanPower-AU2) {
	$collectoraperture = 20.02;
	$collectorgross = 21.80;
}
	$collectorqty = get_post_meta($post->ID, 'RPCollectorQty', true);
	
	// OVERRIDES - If A Specific Gross & Aperture Area Entered, Use Those...Otherwise Use The Calculated Figures
	if (get_post_meta($post->ID, 'RPCollectorGrossArea', true)) {
		$grossarea = get_post_meta($post->ID, 'RPCollectorGrossArea', true);
	} else {
		$grossarea = $collectorqty * $collectorgross;
	}
	if (get_post_meta($post->ID, 'RPCollectorApertureArea', true)) {
		$netaperture = get_post_meta($post->ID, 'RPCollectorApertureArea', true);
	} else {
		$netaperture = $collectorqty * $collectoraperture;
	}
	
// CALCULATIONS FOR ANTICIPATED ENERGY SAVINGS
if (in_category('113')) {
	$systype = 'residential';
} elseif (in_category('114')) {
	$systype = 'residential';
} else {
	$systype = 'commercial';
}

if ($systype == residential) {
	$natgasbtu = 5.000000;
	$electricbtu = 12.879906;
} else {
	$natgasbtu = 5.000000;
	$electricbtu = 12.879906;
}
$heatoilbtu = 6.056652;
$propanebtu = 5.683060;

$systemmbtu = get_post_meta($post->ID, 'RPEnergyProduction', true);
// $systembtu = $systemmbtu * 1000000;

if (get_post_meta($post->ID, 'RPEnergyType', true) == 'Natural Gas') {
	$annualsavings = $systemmbtu * $natgasbtu;
} elseif (get_post_meta($post->ID, 'RPEnergyType', true) == Electric) {
	$annualsavings = $systemmbtu * $electricbtu;
} elseif (get_post_meta($post->ID, 'RPEnergyType', true) == 'Heating Oil') {
	$annualsavings = $systemmbtu * $heatoilbtu;
} else {
	$annualsavings = $systemmbtu * $propanebtu;
}

// Override - If 15Year Savings Is Manually Entered, Use That...If Not, Use The Calculation
	if (get_post_meta($post->ID, 'RP15YearSavings', true)) {
		$echosavings = get_post_meta($post->ID, 'RP15YearSavings', true);
	} else {
		$fifteenyearsavings = $annualsavings * 15;
		$echosavings = number_format($fifteenyearsavings);
	}

// CALUCLATIONS FOR SYSTEM COSTS
$budget = get_post_meta($post->ID, 'RPBudget', true);
$materials = $budget * 0.5;
$materialsfix = number_format($materials);
$labor = $budget * 0.4;
$laborfix = number_format($labor);
$engineering = $budget * 0.1;
$engineeringfix = number_format($engineering);

if ( get_post_meta($post->ID, 'RPBudget', true) ) {
	$budget = get_post_meta($post->ID, 'RPBudget', true);
	$budgetfix = number_format($budget);
} else {
	$budgetfix = 'Unknown';
}

if ( get_post_meta($post->ID, 'RPOtherCosts', true) ) {
	$rpAdditionalCosts =  get_post_meta($post->ID, 'RPOtherCosts', true);
} else {
	$rpAdditionalCosts = 'Unknown';
}

$federalcredit = $budget * 0.3;
$federalcreditfix = number_format($federalcredit);

$rpCustomer = get_post_meta($post->ID, "RPCustomer", true);
$rpConstructionYear = get_post_meta($post->ID, "RPBuildingConstructionYear", true);
$rpLocation = get_post_meta($post->ID, "RPLocation", true);
$rpBuildingType = get_post_meta($post->ID, "RPBuildingType", true);
$rpSystemType = get_post_meta($post->ID, "RPSystemType", true);
$rpCollectorType = get_post_meta($post->ID, "RPCollectorType", true);
$rpCollectorModel = get_post_meta($post->ID, "RPCollectorModel", true);
$rpCollectorQty = get_post_meta($post->ID, "RPCollectorQty", true);
$rpSolarFraction = get_post_meta($post->ID, "RPSolarFraction", true);
$rpDate = get_post_meta($post->ID, "RPDate", true);
$rpEnergyProduction = get_post_meta($post->ID, "RPEnergyProduction", true);
$rpMountingType = get_post_meta($post->ID, "RPMountingType", true);
$rpTankCapacity = get_post_meta($post->ID, "RPTankCapacity", true);
$rpMainImage = get_post_meta($post->ID, "RPMainImage", true);
$rpAddImage = get_post_meta($post->ID, "RPAddImage", true);
$rpPrintDescription = get_post_meta($post->ID, "RPPrintDescription", true);

$pdf_html_header 			= true; //If this is ture you can write instead of the array a html string on the var $pdf_header
$pdf_html_footer 			= true; //If this is ture you can write instead of the array a html string on the var $pdf_footer

$pdf_header = '

';

$pdf_footer = '
	<div id="footer">
		<div style="width:100%;height:1px;background-color:#666666;">&nbsp;</div>
		<div id="footer-left">
			<ul>
				<li>' . $dsProductWarranty . '</li>
				<li>' . $dsProductSRCC . '</li>
				<li>' . $dsProductKeymark . '</li>
				<li>' . $dsProductCSA . '</li>
			</ul>
			<p style="font-size:11px;font-style:italic;">&copy;2012 SunMaxx Solar<br>Energy Production &amp; Savings Based On Engineering Caluclations, Real World Performance May Vary.</p>
		</div>
		<div id="footer-right">
			<p><strong>SunMaxx Solar</strong><br />
			56 Broome Corporate Pkwy<br />
			Conklin, NY 13748<br />
			P: 1.877.786.6299<br />
			F: 1.800.786.0329<br />
			www.SunMaxxSolar.com</p>
		</div>
	</div>
';
		

	$pdf_output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
		<html xml:lang="en">
		
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
			<title>' . get_bloginfo() . '</title>
			
		</head>
		
		<body xml:lang="en">
		
			<bookmark content="'.htmlspecialchars(get_bloginfo('name'), ENT_QUOTES).'" level="0" /><tocentry content="'.htmlspecialchars(get_bloginfo('name'), ENT_QUOTES).'" level="0" />
			
			<style>
				
				@page { size: 8.5in 11in; }
				
				body { font-family:arial;font-size:12px; }
				a { color:#002d55;text-decoration:none; }
				h2 { display:block;padding-left:10px;height:30px;line-height:30px;background:#022d55;font-size:12px;font-weight:bold;color:#ffffff;margin:0px;margin-bottom:10px; }
				h3 { display:block;padding-left:10px;height:30px;line-height:30px;background:#e77d1d;font-size:12px;font-weight:bold;color:#ffffff;margin:0px;margin-bottom:10px; }
					#printRPRight h3 { margin:0px; }
					
				#wrapper { ;padding:0px;margin:0px; }
				
				#header-left { width:500px;float:left;margin:0px; }
					#header-left img { width:500px;margin:0px;clear:none; }
					#header-left h1 { font-family:arial;font-size:18px;font-weight:bold;line-height:18px;margin:0px;margin-bottom:-20px; }
				#header-right-address { float:right;margin:0px;text-align:right; }
				
				#printRPleft { width:60%;float:left;margin:0px; }
				#printRPRight { width:35%;float:right;margin:0px;padding-top:3px; }
					#printRPRightQuick { width:95%;padding:2%;border:#cccccc .5% solid;background:#f2f2f2; }
						#printRPRightQuick ul { list-style:none;padding:0px;margin:0px;font-size:10px;width:100%; }
							#printRPRightQuick ul li { display:block;width:100%;height:20px;line-height:20px;font-weight:bold; }
								#printRPRightQuick span { text-align:right !important;font-weight:normal; }
								
				#footer { width:100%;border-top:#666666 1px solid; }
					#footer p { font-size:12px;color:#666666; }
					#footer-left { width:65%;float:left;margin:0px; }
					#footer-right { width:30%;float:right;margin:0px;border-left:#666666 1px solid;text-align:right; }
				
				
			</style>
			
			<div id="wrapper">
	<div id="header">
    	<div id="header-left">
			<img src="images/printRPlogo.jpg" />
        </div>
        <div id="header-right-address">
        	<p>
            	<strong>SunMaxx Solar</strong><br />
                56 Broome Corp Pkwy<br />
                Conklin, NY 13748<br />
                P: 1.877.786.6299<br />
                <a href="http://www.sunmaxxsolar.com"><strong>www.SunMaxxSolar.com</strong></a></p>
            </p>
        </div>
        <div style="width: 1000px; height: 5px; clear: both; background-color: #e77d1d; margin-bottom: 10px;"></div>
        
        <div style="width: 1000px; height: 0px; clear: both;"></div>
        
	</div>  
<div style="width: 1000px; height: 20px; clear: both;"></div>
			
			<div id="printRPLeft">';
			
			while (have_posts()) : the_post();
			
				$cat_links = "";
				foreach((get_the_category()) as $cat) {
					$cat_links .= '<a href="' . get_category_link($cat->term_id) . '" title="' . $cat->category_description . '">' . $cat->cat_name . '</a>, ';
				}
				$cat_links = substr($cat_links, 0, -2);

				$pdf_output .= '<bookmark content="'.the_title('','', false).'" level="1" /><tocentry content="'.the_title('','', false).'" level="1" />';
				$pdf_output .= '<div class="post">
				<h2>' . $rpCustomer . '</h2>
				<p>' . $rpPrintDescription . '</p>';

				$pdf_output .= '
					<h3 style="margin-bottom:0px;">Building Details</h3>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:10px;">
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Building Type</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpBuildingType . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Construction Year</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpConstructionYear . '</td>
						</tr>
					</table>
					<h3 style="margin:0px;margin-top:10px;">Solar System Details</h3>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:10px;">
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Solar Thermal System Type</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpSystemType . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Energy Production</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpEnergyProduction . ' MMBTU</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Anticipated Solar Fraction</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpSolarFraction . '%</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Type Of Solar Collectors</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpCollectorType . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Solar Collector Model</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpCollectorModel . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;"># Of Solar Collectors</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpCollectorQty . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Collector Gross Area (ft2)</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $grossarea . ' ft2</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Net Aperture Area (ft2)</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $netaperture . ' ft2</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Type Of Mounting System</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpMountingType . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Storage Tank Capacity (G)</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">' . $rpTankCapacity . '</td>
						</tr>
					</table>
					<h3 style="margin:0px;margin-top:10px;">Financial Details</h3>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:10px;">
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Proposed System Budget</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $budgetfix . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Solar Materials Cost</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $materialsfix . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Installation Cost</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $laborfix . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Engineering Services Cost</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $engineeringfix . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Additional Costs</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $rpAdditionalCosts . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Anticipated 15 Year Energy Savings</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $echosavings . '</td>
						</tr>
						<tr>
							<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;padding-left:10px;">Federal Rebates &amp; Credits</td>
							<td align="right" style="height:20px;line-height:20px;padding-right:10px;">$ ' . $federalcreditfix . '</td>
						</tr>
					</table>
				';
				
				if(!is_page() && !is_single()) $pdf_output .= '<p class="postmetadata">Posted in ' . $cat_links . ' | ' . '<a href="' . get_permalink() . '#comment">' . $comment_link . '</a></p>';

				$pdf_output .= '</div> <!-- post -->';
			endwhile;

		$pdf_output .= '</div> <!--printRPLeft-->
						<div id="printRPRight">
							<h3>Project Quick Reference</h3>
							<div id="printRPRightQuick">
								<table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:10px;">
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;padding:0px;margin:0px;">Customer</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpCustomer . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Location</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpLocation . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Building Type</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpBuildingType . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">System Type</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpSystemType . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Collector Type</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpCollectorType . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Collector Model</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpCollectorModel . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;"># Of Collectors</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpCollectorQty . '</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Solar Fraction</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpSolarFraction . '%</td>
								</tr>
								<tr>
									<td align="left" style="height:20px;line-height:20px;font-weight:bold;">Install Date</td>
									<td align="right" style="height:20px;line-height:20px;">' . $rpDate . '</td>
								</tr>
							</table>
							</div>
						<h3 style="margin:0px;margin-top:10px;">Project Overview</h3>
						<div style="height:480px;font-size:11px;">
							<p><img src="http://www.sunmaxxsolar.com/'.$rpMainImage.'" width="245" /></p>
							<p><img src="http://www.sunmaxxsolar.com/'.$rpAddImage.'" width="245" /></p>
						</div>

		</div>';

	$pdf_output .= '
		</div>';
	
	$pdf_output .= '
		</body>
		</html>';
?>
